package summary;

/**
 * @Author: 海琳琦
 * @Date: 2022/3/9 11:09
 * https://leetcode-cn.com/problems/ransom-note/
 */
public class Title383 {

    public boolean canConstruct(String ransomNote, String magazine) {
        int[] record = new int[26];
        for (int i = 0; i < magazine.length(); i++) {
            record[magazine.charAt(i) - 'a']++;
        }
        for (int i = 0; i < ransomNote.length(); i++) {
            if (--record[ransomNote.charAt(i) - 'a'] < 0) {
                return false;
            }
        }
        return true;
    }










    public boolean canConstruct11(String ransomNote, String magazine) {
        int[] arr = new int[26];
        for (int i = 0; i < magazine.length(); i++) {
            arr[magazine.charAt(i) - 'a'] += 1;
        }
        for (int i = 0; i < ransomNote.length(); i++) {
            if (--arr[ransomNote.charAt(i) - 'a'] <0) {
                return false;
            }
        }
        return true;
    }












    public static void main(String[] args) {

    }
}
